const app = getApp();

let tabberNum = Behavior({
    // 共享属性
    properties: {
        //   noticeNum: Number,
        //   exNum: Number,
        //   mineNum: Number,
    },
    // 共享数据
    data: {
        noticeNum: '',
        exNum: '',
        mineNum: '',
    },
    // 共享方法
    methods: {
        behaviorTap() {
            this.setData({
                noticeNum:
                    app.globalData.nqModuleCount > 99
                        ? 99
                        : app.globalData.nqModuleCount,
                exNum:
                    app.globalData.exModuleCount > 99
                        ? 99
                        : app.globalData.exModuleCount,
                mineNum:
                    app.globalData.mineModuleCount > 99
                        ? 99
                        : app.globalData.mineModuleCount,
            });
        },
    },
});

const scrollToLeftEnd = Behavior({
    // 共享数据
    data: {
        _touch: {
            x: null,
            y: null,
        },
    },
    // 共享方法
    methods: {
        _touchStart(e) {
            if (e.target.id === 'scroll-big-photo') return;
            this.setData({
                '_touch.x': e.changedTouches[0].clientX,
                '_touch.y': e.changedTouches[0].clientY,
            });
        },

        _touchEnd(e) {
            if (e.target.id === 'scroll-big-photo') return;
            let endX = e.changedTouches[0].clientX;
            let endY = e.changedTouches[0].clientY;
            const direction = this._getTouchData(
                endX,
                endY,
                this.data._touch.x,
                this.data._touch.y
            );
            if (direction === 'right') {
                wx.navigateBack({
                    detal: 1,
                });
            }
        },

        /***
         * 判断用户滑动
         * 左滑还是右滑
         */
        _getTouchData(endX, endY, startX, startY) {
            let turn = '';
            if (endX - startX > 50 && Math.abs(endY - startY) < 50) {
                //右滑
                turn = 'right';
            } else if (endX - startX < -50 && Math.abs(endY - startY) < 50) {
                //左滑
                turn = 'left';
            }
            return turn;
        },
    },
});

const touchFromTheLeftEdge = Behavior({
    data: {
        _scrollY: true,
    },
    methods: {
        _touchFromTheLeftEdge(e) {
            const clientX = e.touches[0].clientX;
            if (clientX < 30) {
                this.setData({
                    _scrollY: false,
                });
            } else {
                this.setData({
                    _scrollY: true,
                });
            }
        },
    },
});
export { tabberNum, scrollToLeftEnd, touchFromTheLeftEdge };
